/**
  **************************************************************************
  * @file     usart.h
  * @brief    usart header file
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

#ifndef __USART_H
#define __USART_H

#ifdef __cplusplus
extern "C" {
#endif

#include "at32f403a_407_board.h"

/** @addtogroup UTILITIES_examples
  * @{
  */
//#define DEBUG

#ifdef  DEBUG
#define DbgPrintf(format, ...)  printf (format, ##__VA_ARGS__)
//#define DbgPrintf(format,...) printf("File: "__FILE__", Line: %05d: "format"\n", __LINE__, ##__VA_ARGS__)  
#define dd(...) dl_log(DL_LOG_DEBUG, __VA_ARGS__)
#define di(...) dl_log(DL_LOG_INFO, __VA_ARGS__)
#define dn(...) dl_log(DL_LOG_NOTICE, __VA_ARGS__)
#define dw(...) dl_log(DL_LOG_WARN, __VA_ARGS__)
#define de(...) dl_log(DL_LOG_ERR, __VA_ARGS__)

#else  

#define DbgPrintf(format,...) 

#define dd(...)
#define di(...)
#define dn(...)
#define dw(...)
#define de(...)

#endif  




/** @addtogroup USART_iap_bootloader
  * @{
  */

/** @defgroup bootloader_definition
  * @{
  */

#define USART_REC_LEN      256

/**
  * @}
  */

/** @defgroup bootloader_exported_types
  * @{
  */
typedef struct
{
    uint32_t baud_rate ; 
    usart_data_bit_num_type data_bit; 
    usart_stop_bit_num_type stop_bit;
    usart_parity_selection_type parity;
}usart_config;
/**
  * @brief  usart group type
  */
typedef struct
{
    uint8_t DMARx[USART_REC_LEN];
}usart_dma_type;

/**
  * @}
  */

extern usart_dma_type usart_dma_buff[];

/** @defgroup bootloader_exported_functions
  * @{
  */

void board_usart1_init(void);
void board_usart2_init(void);
void board_usart3_init(void);
void board_uart4_init(void);
void board_uart5_init(void);
void board_usart6_init(void);
void board_uart7_init(void);
void board_uart8_init(void);


void USART_DMA_Receive_Data(usart_type* usart_x);
void rs485_send_data(usart_type* usart_x,uint8_t* buf, uint16_t cnt);

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif
